from gate import create_app
import unittest
import operator
from flask import Flask, Response
import types

class PartnerGateTestCase(unittest.TestCase):
    def setUp(self):
        self.app = create_app().test_client()
        #insert some test data in database
        #setup database
        #clear tables

    def tearDown(self):
        #close database
        pass

    def test_bogus(self):
        response = self.app.get("/12435/23423432")
        self.assert200(response)
        self.assertEqual(response.data, "0")

    def test_bogus2(self):
        response = self.app.get("/doug")
        self.assert200(response)
        self.assertEqual(response.data, "0")

    def test_full_cycle(self):
        response = self.app.get("/50001/e018e2d49783e212c38c33f69fed6c01")
        self.assert200(response)
        first = self.assertNotEqual(response, "0")
        
        response = self.app.get("/50001/e018e2d49783e212c38c33f69fed6c01/")
        self.assert200(response)
        second = self.assertNotEqual(response, "0")
    
        self.assertEqual(first, second)

        response = self.app.get("/total/50001/")
        self.assert_total(response, "1")

    def replay_log(self):
        pass

    # utility methods
    def assert_response_ne(self, response, notExpected):
        self.assert200(response)
        self.assertTrue(operator.ne(response.data, notExpected))
        return response.data

    def assert_response(self, response, operator, expectedResponse):
        self.assert200(response)
        self.assertTrue(operator(response.data, expectedResponse))
        return response.data

    def assert_total(self, response, expected_total):
       self.assert200(response)
       total = response.data
       assert total == expected_total 

    def assert200(self, response):
        self.assert_status(response, 200)

    def assert_status(self, response, status_code):
        self.assertEqual(response.status_code, status_code)

if __name__ == "__main__":
    unittest.main()
